         <!-- START OF MAINCOL -->
          <div class="MainCol AM_BookPage">

              <h1 class="left">编辑文章</h1>
              <div class="right"><a href="<?php echo CHtml::normalizeUrl(array('/admin/posts/postnew')); ?>" class="Blue_btn" title="add new ebook"><span><?= CHtml::image(Yii::app()->baseUrl.'/images/add_icon.gif', '', array('class' => 'icon')); ?> 添加新文章</span></a>
              </div>
              <br class="clear" />
              
              <span class="NormalFont SmallFont">
                  <?= CHtml::image(Yii::app()->baseUrl.'/images/home_icon.gif', '主页'); ?> > 文章管理 > 编辑文章
               </span><br /><br />
              
              <?php echo CHtml::form(array('/admin/posts/search'), 'GET');  ?>
              <input type="text" name="key" class="TxtInput" value="<?php echo isset($key) ? $key : '' ?>" />
              <select>
              	<option>标题</option>
              </select>
              <?php echo CHtml::submitButton('搜索') ?>
              <?php echo CHtml::endForm() ?>
              
              <div class="Titlebox box"><!-- DON'T DELETE --></div>

              <?php if(Yii::app()->user->hasFlash('message')) : ?>
              <div class="SuccessfulBox Smallbox">
                <span class="Successful"> <?php echo Yii::app()->user->getFlash('message'); ?></span>
              </div>
              <?php endif; ?>
              
              <div class="DisplayBox_top Smallbox">
              
              	  <b class="left SmallFont">显示 <span class="Blue"><?= $pages->startOffset; ?> - <?= $pages->endOffset; ?> , 共 <?= $pages->itemCount; ?></span> 条记录</b>
                  
                  <?php $this->widget('CListPager', array('pages' => $pages)); ?>
                  <?php // $this->widget('CLinkPager', array('pages' => $pages, 'maxButtonCount' => 8)); ?>
                  
                  <br class="clear" />
              </div>
              
              <ul class="Lists Smallbox">
              <?php $categoriesDropDownList = $this->createWidget('CategoriesDropDownList') ?>
              <?php foreach($posts as $k => $post) { ?>
              	  <li <?php if($k%2 == 1) { ?>class="ThinGrey_bg"<?php } ?>>
                      
                      <span class="ContentBox">
                          <p class="Smallbox">
                      	  <?= CHtml::link($post->postTitle, array('admin/posts/edit', 'id' => $post->postId), array('class' => 'NameLink')); ?><br />
                      	    ID：<?php echo $post->postId; ?>&nbsp;&nbsp;&nbsp;&nbsp;
                          	作者: <?= $post->author->userName() ; ?>,
                          	提交时间: <?= date('y年m月d日 H:i', $post->postDate); ?>
                          </p>
                          
                          <p class="Smallbox">
                          <label>话题</label>:
                          <?php $options = CHtml::listData($topics, 'termTaxonomyId', 'terms.name'); ?>
                          <?= CHtml::activeDropDownList($post->hasTopic() ? $post->topics[0] : new TermsTaxonomy, 'termTaxonomyId', $options, array('class' => 'Select', 'name' => 'topic', 'empty' => '-- 请选择话题 --')); ?><input type="button" style="display:none" id="update_topic_post_<?php echo $post->postId ?>" value="确认" class="update-topic-btn" /><span></span><br />
                          <label>分类</label>: <?php $categoriesDropDownList->setSelectedId($post->categories[0]->termTaxonomyId)->renderContent() ?><input type="button" style="display:none" value="确认" id="update_category_post_<?php echo $post->postId ?>" class="update-category-btn" /><span></span><br />
                          <label>内容</label>: <?= truncStr(strip_tags($post->postContent), 240, '...'); ?><br />
                          </p>
                      </span>
                      <br class="clear" />
                      
                      <span class="Rated"><?php echo CHtml::link('删除', array('/admin/posts/delete', 'id' => $post->postId), array('confirm' => '确定要删除这篇文章吗？', 'class' => 'Delete')); ?></span>
                </li>
                <?php } ?>
                
              </ul>
              
              
              <div class="DisplayBox_btm">
              
              	  <b class="left SmallFont">显示 <span class="Blue"><?= $pages->startOffset; ?> - <?= $pages->endOffset; ?> , 共 <?= $pages->itemCount; ?></span> 条记录</b>
                  
                  <?php $this->widget('CListPager', array('pages' => $pages)); ?>
                  <?php // $this->widget('CLinkPager', array('pages' => $pages)); ?>
                  
                  <br class="clear" />       
              </div>
              
        </div>
          <!-- END OF MAINCOL -->
      <script type="text/javascript">
      $(document).ready(function() {
          var tick = '<img src="<?php echo Yii::app()->baseUrl.'/images/write_ok.gif' ?>" alt="Success" />';

          $('.update-category-btn').prev('select').change(function() {
				$(this).next('input').show();
				$(this).next('input').next('span').html('');
          });

          $('.update-topic-btn').prev('select').change(function() {
				$(this).next('input').show();
				$(this).next('input').next('span').html('');
      	  });
      	  
         $('.update-category-btn').click(function() {
            btnId = $(this).attr('id');
            position = btnId.lastIndexOf('_')+1;
            postId = parseInt(btnId.substr(position));

            categoryId = $(this).prev('select').val();
            var _this = $(this);
            _this.next('span').html('');
            $.post("<?php echo CHtml::normalizeUrl(array('/admin/posts/updatecategory')) ?>",
                {postId : postId, categoryId : categoryId},
                function(data) {
                    result = parseInt(data);
                    if(result == 1) {
                        _this.next('span').html(tick);
                        _this.hide();
                    } else {
                        alert('修改文章分类失败！');
                    }
                }
            );
         });

         $('.update-topic-btn').click(function() {
            btnId = $(this).attr('id');
            position = btnId.lastIndexOf('_')+1;
            postId = parseInt(btnId.substr(position));

            topicId = $(this).prev('select').val();
            var _this = $(this);
            _this.next('span').html('');

            $.post("<?php echo CHtml::normalizeUrl(array('/admin/posts/updatetopic')) ?>",
                {postId : postId, topicId : topicId},
                function(data) {
                    result = parseInt(data);
                    if(result == 1) {
                        _this.next('span').html(tick);
                        _this.hide();
                    } else {
                        alert('修改文章话题失败！');
                    }
                }
            );
         });
      });
      </script>